package com;

public class Homework {
    public static void main(String[] args) {
        MylinkList arr1 = new MylinkList();
        MylinkList arr2 = new MylinkList();
        arr1.add(3);arr1.add(5);arr1.add(7);arr1.add(12);arr1.add(14);arr1.add(15);
        arr2.add(4);arr2.add(5);arr2.add(9);arr2.add(16);arr2.add(17);arr2.add(66);

        function1(arr1,arr2);


    }


     /**
     *不改变原数组的合并 + 结果打印
     **/
    public static void function1(MylinkList arr1 , MylinkList arr2){
        Node first1 = arr1.first; Node first2 = arr2.first; Node resultFirst =null; Node resultIndex;
        if (first1.date > first2.date){
            resultFirst = first2;
            resultIndex = first2;
            first2 = first2.next;
        }else {
            resultFirst = first1;
            resultIndex = first1;
            first1 = first1.next;
        }
        while (true ){
            if (first1 == null){
                resultIndex.next = first2;
                break;
            }
            if (first2 == null){
                resultIndex.next = first1;
                break;
            }
            if (first1.date > first2.date){
                resultIndex.next = first2;
                resultIndex = resultIndex.next;
                first2 = first2.next;
            }
            else{
                resultIndex.next = first1;
                resultIndex = resultIndex.next;
                first1 = first1.next;
            }
        }

        Node hello = resultFirst;
        for (int i = 0 ;  i < arr1.num+arr2.num ; i++) {
            System.out.print(hello.date+" ");
            hello = hello.next;
        }
    }
}
